#!/usr/bin/python

#
# v0.1, just starting up.
#

import flickrapi, os
from flickrapi.tokencache import LockingTokenCache


#making sure the config folder exists
if not os.access('~/.pyFlickrSync/',os.F_OK): os.mkdir('~/.pyFlickrSync/')
# TODO: if not os.access('~/.pyFlickrSync/',os.R_OK): exit()

api_key = '45f482e873b007516b5103923c520b6b'
api_secret = '72503593d1e2c2d5'

flickr = flickrapi.FlickrAPI(api_key, api_secret, cache=True)
flickr.cache = flickrapi.SimpleCache(timeout=300, max_entries=200) #TODO : tweak the cache
flickr.token.path = '~/.pyFlickrSync/auth.token'
#ensures that only one time the api key is used
flickr.token_cache = LockingTokenCache(api_key)

#first authentication

#this will open a browser if the token can't be authenticated
(token, frob) = flickr.get_token_part_one(perms='write') # may need to change to delete to allow also to take pictures off flickr.
# halting if not authenticated
if not token: raw_input("Press ENTER after you authorized this program")
# stores the token in the cache
flickr.get_token_part_two((token, frob))

# TODO: process one main path, include option to do subpaths if they are not in a .skiplist of the main path. should follow symlink.
# TODO: per folder .skiplist file with all files that must be skipped. include option about the case.
# TODO: create a db with all the set names ; if tags have one of those names, they are assigned to the set and possibly removed from the picture. 
